package com.googlecode.hmvc4gwt.example.hmvcblog.service.gwtrpc.server.blog.entry;

import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.BlogIdDTO;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.BlogEntryDTO;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.BlogEntryEditDTO;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.BlogEntryNewDTO;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.BlogEntryRemoveDTO;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.BlogEntryUpdateDTO;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.exceptions.BlogEntryNotFoundException;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.exceptions.BlogEntryTextEmptyException;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.entry.exceptions.BlogEntryTitleEmptyException;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.exceptions.BlogNotFoundException;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.blog.exceptions.NotBlogOwnerException;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.dto.user.exception.NotLoggedInException;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.gwtrpc.client.blog.entry.IBlogEntryRemoteService;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.gwtrpc.server.ApplicationContext;
import com.googlecode.hmvc4gwt.example.hmvcblog.service.services.blog.entry.IBlogEntryService;

public class BlogEntryRemoteServiceImpl extends RemoteServiceServlet implements IBlogEntryRemoteService {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;
	
	private IBlogEntryService blogEntryService;

	public BlogEntryRemoteServiceImpl() {
		setBlogEntryService((IBlogEntryService) ApplicationContext.getBean("blogEntryService"));
	}
	
	public void addBlogEntry(BlogEntryNewDTO blogEntryNewDTO) throws NotLoggedInException, NotBlogOwnerException, BlogNotFoundException, BlogEntryTitleEmptyException, BlogEntryTextEmptyException {
		
		try {
			getBlogEntryService().addBlogEntry(blogEntryNewDTO);
		} catch (com.googlecode.hmvc4gwt.example.hmvcblog.server.repository.blog.exceptions.BlogNotFoundException e) {
			throw new BlogNotFoundException();
		}
		
	}

	public void editBlogEntry(BlogEntryEditDTO blogEntryEditDTO) throws NotLoggedInException, NotBlogOwnerException, BlogEntryTitleEmptyException, BlogEntryTextEmptyException, BlogEntryNotFoundException {
		getBlogEntryService().editBlogEntry(blogEntryEditDTO);
	}

	public IBlogEntryService getBlogEntryService() {
		return blogEntryService;
	}

	public List<BlogEntryDTO> getListBlogEntry(BlogIdDTO blogIdDTO) throws BlogNotFoundException {
		try {
			return getBlogEntryService().getListBlogEntries(blogIdDTO);
		} catch (com.googlecode.hmvc4gwt.example.hmvcblog.server.repository.blog.exceptions.BlogNotFoundException e) {
			throw new BlogNotFoundException();
		}
		
		
		
	}

	public void removeBlogEntry(BlogEntryRemoveDTO blogEntryRemoveDTO) throws NotLoggedInException, NotBlogOwnerException, BlogEntryNotFoundException {
		getBlogEntryService().removeBlogEntry(blogEntryRemoveDTO);
	}

	public void setBlogEntryService(IBlogEntryService blogEntryService) {
		this.blogEntryService = blogEntryService;
	}

	public void updateBlogEntry(BlogEntryUpdateDTO blogEntryUpdateDTO)
			throws NotLoggedInException, NotBlogOwnerException,
			BlogNotFoundException, BlogEntryNotFoundException,
			BlogEntryTextEmptyException {
		// TODO Auto-generated method stub
		
	}

}
